package com.chixing.day10.HashCode;

import java.util.Objects;

public class Student {
    private int stuId;
    private String stuName;
    private String stuMajor;
    private long stuTelno;

    public Student() {
    }

    public Student(int stuId, String stuName, String stuMajor, long stuTelno) {
        this.stuId = stuId;
        this.stuName = stuName;
        this.stuMajor = stuMajor;
        this.stuTelno = stuTelno;
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public String getStuMajor() {
        return stuMajor;
    }

    public void setStuMajor(String stuMajor) {
        this.stuMajor = stuMajor;
    }

    public long getStuTelno() {
        return stuTelno;
    }

    public void setStuTelno(long stuTelno) {
        this.stuTelno = stuTelno;
    }

    //重写equals方法 :因为比较两个对象是不是同一个对象,业务中要比较而是内容值,而不是内存地址。但是Object.equals()
    //               比较的还是内存地址,所以业务中需要重写equals方法
    @Override
    public boolean equals(Object obj) {
//        if(obj == null || this.getClass() != obj.getClass()) {
//            return false;
//        }
//        if(obj == this) {
//            return true;
//        }

        Student anotherSu = (Student) obj;
        if (this.stuId != anotherSu.stuId) {
            return false;
        }
        if (this.stuName != anotherSu.stuName) {
            return false;
        }
        if (this.stuMajor != anotherSu.stuMajor) {
            return false;
        }
        if (this.stuTelno != anotherSu.stuTelno) {
            return false;
        }
        return true;
    }


    @Override
    public int hashCode() {
        return Objects.hash(stuId, stuName, stuMajor, stuTelno);
    }

    @Override
    public String toString() {
        return "Student{" +
                "stuId=" + stuId +
                ", stuName='" + stuName + '\'' +
                ", stuMajor='" + stuMajor + '\'' +
                ", stuTelno=" + stuTelno +
                '}';
    }
}
